package com.yoki.cloud.common.protocol.radius.attribute.attr.acct;

import com.yoki.cloud.common.protocol.radius.attribute.attr.type.IntegerTypeAttr;
import lombok.Getter;

/**
 * @author Sky$
 * @Description: TODO
 * @date 2018/1/15$ 14:54$
 */
public class AcctTerminateCauseAttr extends IntegerTypeAttr {

    public static final int ATTR_TYPE = 49;

    @Override
    public int getAttrType() {
        return ATTR_TYPE;
    }

    public AcctTerminateCauseTypeEnum getAcctTerminateCauseType() {
        return AcctTerminateCauseTypeEnum.getByValue(this.value);
    }

    public enum AcctTerminateCauseTypeEnum {

        UserRequest(1, "User Request"),
        LostCarrier(2, "Lost Carrier"),
        LostService(3, "Lost Service"),
        IdleTimeout(4, "Idle Timeout"),
        SessionTimeout(5, "Session Timeout"),
        AdminReset(6, "Admin Reset"),
        AdminReboot(7, "Admin Reboot"),
        PortError(8, "Port Error"),
        NASError(9, "NAS Error"),
        NASRequest(10, "NAS Request"),
        NASReboot(11, "NAS Reboot"),
        PortUnneeded(12, "Port Unneeded"),
        PortPreempted(13, "Port Preempted"),
        PortSuspended(14, "Port Suspended"),
        ServiceUnavailable(15, "Service Unavailable"),
        Callback(16, "Callback"),
        UserError(17, "User Error"),
        HostRequest(18, "Host Request");

        @Getter
        private int value;
        @Getter
        private String name;

        AcctTerminateCauseTypeEnum(int value, String name) {
            this.value = value;
            this.name = name;
        }

        public static AcctTerminateCauseTypeEnum getByValue(Integer value) {
            if (null == value) {
                throw new IllegalArgumentException();
            }
            AcctTerminateCauseTypeEnum[] enums = AcctTerminateCauseTypeEnum.values();
            for (AcctTerminateCauseTypeEnum e : enums) {
                if (e.getValue() == value.intValue()) {
                    return e;
                }
            }
            return null;
        }

    }

}
